﻿var columns =
            [
                 { display: 'Key', name: 'Id', type: 'text', hide: 1 },
                  { display: 'BillState', name: 'BillState', type: 'text', hide: 1 },
                { display: '工作组', name: 'RefeName', mintWidth: 80, width: 120 },
                 { display: '计件人员', name: 'WorkGroupName', mintWidth: 80, width: 120 },
                  { display: '是否组长', name: 'IsHeadmanName', mintWidth: 80, width: 120 },
                { display: '工序', name: 'ProductProcedureName', mintWidth: 80, width: 120 },
                { display: '计件数量', name: 'PieceCount', mintWidth: 80, width: 140 },
                { display: '单据状态', name: 'BillStateName', mintWidth: 80, width: 80 },
                 { display: '结算工资状态', name: 'SettleState', mintWidth: 80, width: 120 },
                  { display: '日期', name: 'SubmitDate', type: 'selfDate', mintWidth: 160, width: 160 }
             ];

var manager;
//init controls
$(document).ready(function () {
    initligerGrid();
    initDataControls();
    $("#btnSearch").unbind("click").bind("click", initligerGrid);
});

function initligerGrid() {
    manager = null;
    manager = $("#PieceGrid").ligerGrid({
        columns: columns,
        title: '计件列表',
        showTitle: true,
        width: '100%',
        enabledSort: true,
        height: '99%',
        checkbox: false,
        rownumbers: true,
        toolbar: { items: [
                                    { text: '增加', click: dialogAdd, icon: 'add' },
                                    { line: true },
                                    { text: '修改', click: modifyOperation, icon: 'modify' },
                                  //  { line: true },
            //                                    { text: '删除', click: deleteOperation, img: '../Content/images/delete.gif' }
                                    { line: true },
                                    { text: '查看', click: dialogDetailView, img: '../Content/images/Search.png' }
                                    ]
        },
        url: "../Piece/GetJsonOfPiece?rand=" + Math.random(),
        parms: { userName: $("#userName").val(), StartDate: $("#StartDate").val(), EndDate: $("#EndDate").val() },
        onDblClickRow: function (data, rowindex, rowobj) { dialogView(data.Id); }
    });
}


//detail
function dialogDetailView() {
    var row = manager.getSelectedRow();
    if (!row) { $.ligerDialog.success('请选择要查看的行!'); return; }
    var billId = row["Id"].toString()
    dialogView(billId);
  }
function dialogView(billId) {
    $.ligerDialog.open({ url: "../Piece/PieceDetail?id=" + billId, height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false });
}
//add
function dialogAdd() {
    $.ligerDialog.open({ url: '../Piece/Add', height: getDialogHeight(), width: getDialogWidth(), 
    isResize: true, isHidden: false
    });
}

//delete
//function deleteOperation() {
//    var row = manager.getSelectedRow();
//    if (!row) { $.ligerDialog.success('请选择需要删除行！'); return; }
//    $.ligerDialog.confirm('确定要删除吗？', function (yes) {
//        if (yes) {
//            $.get("../Piece/Delete?id=" + row["Id"].toString(), {}, function (data) {
//                if (data != undefined && data == "9") {
//                    initligerGrid();
//                }
//            });
//        }
//    });
//}
//update 
function modifyOperation() {
    var row = manager.getSelectedRow();
    if (!row) {
        $.ligerDialog.success('请选择要编辑的行!'); return;
    }
    if (row["BillState"].toString() == "1") { $.ligerDialog.success('已提交，不能修改!'); return; }
    $.ligerDialog.open({ url: '../Piece/Add?id=' + row["Id"].toString(), height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false
    });
  
}

//初始化时间
function initDataControls() {
        $("#StartDate").ligerDateEditor({ showTime: true, format: "yyyy-MM-dd", labelWidth: 140, labelAlign: 'left' });
        $("#EndDate").ligerDateEditor({ showTime: true, format: "yyyy-MM-dd", labelWidth: 140, labelAlign: 'left' });
}